﻿using System;

namespace BearPaw.Core
{
    public class FileContentType
    {
        public int Id { get; set; }
        public int MimeType { get; set; }
        public string Extension { get; set; }

        public static FileContentTypeEnum GetEnumTypeByMimeType(string p)
        {
            switch (p.ToLower())
            {
                case "text/xml":
                    return FileContentTypeEnum.XML;

                case "text/html":
                    return FileContentTypeEnum.HTML;

                case "image/gif":
                    return FileContentTypeEnum.GIF;

                case "image/jpeg":
                    return FileContentTypeEnum.JPG;

                case "image/png":
                    return FileContentTypeEnum.PNG;

                case "image/bmp":
                    return FileContentTypeEnum.BMP;

                case "video/mpeg":
                    return FileContentTypeEnum.MPEG;

                case "video/quicktime":
                    return FileContentTypeEnum.QUICKTIME;

                case "video/x-msvideo":
                    return FileContentTypeEnum.XMSVIDEO;

                case "application/x-shockwave-flash":
                    return FileContentTypeEnum.SWF;

                default:

                    throw new Exception("Unknown mime type");
            }
        }

        public static FileContentTypeEnum GetMimeTypeByExtension(string extension)
        {

            switch (extension.ToLower())
            {
                case "xml":
                    return FileContentTypeEnum.XML;

                case "html":
                    return FileContentTypeEnum.HTML;

                case "gif":
                    return FileContentTypeEnum.GIF;

                case "jpg":
                    return FileContentTypeEnum.JPG;

                case "jpeg":
                    return FileContentTypeEnum.JPG;

                case "png":
                    return FileContentTypeEnum.PNG;

                case "bmp":
                    return FileContentTypeEnum.BMP;

                case "mpg":
                    return FileContentTypeEnum.MPEG;

                case "mov":
                    return FileContentTypeEnum.QUICKTIME;

                case "avi":
                    return FileContentTypeEnum.XMSVIDEO;

                case "swf":
                    return FileContentTypeEnum.SWF;

                default:

                    throw new Exception("Unknown extension type");
            }
        }

        public static string GetMimeType(FileContentTypeEnum type)
        {
            switch (type)
            {
                case FileContentTypeEnum.XML:
                    return "text/xml";

                case FileContentTypeEnum.HTML:
                    return "text/html";

                case FileContentTypeEnum.GIF:
                    return "image/gif";

                case FileContentTypeEnum.JPG:
                    return "image/jpeg";

                case FileContentTypeEnum.PNG:
                    return "image/png";

                case FileContentTypeEnum.BMP:
                    return "image/bmp";

                case FileContentTypeEnum.MPEG:
                    return "video/mpeg";

                case FileContentTypeEnum.QUICKTIME:
                    return "video/quicktime";

                case FileContentTypeEnum.XMSVIDEO:
                    return "video/x-msvideo";

                case FileContentTypeEnum.SWF:
                    return "application/x-shockwave-flash";

                default:

                    throw new Exception("Unknown mime type");
            }
        }
        public enum FileContentTypeEnum
        {
            //TODO: to database
            XML = 0,
            HTML = 1,
            GIF = 2,
            JPG = 3,
            PNG = 4,
            MPEG = 5,
            QUICKTIME = 6,
            XMSVIDEO = 7,
            SWF = 8,
            BMP = 9
        }
    }
}
